import './spd-img.less';
import { useState, useEffect } from 'react';
export function SpdBgImg(props: {defaultSrc: string, src?: string}) {
    let [style, setStyle] = useState(props.defaultSrc);
    useEffect(() => {
        if(typeof props.src == 'string') {
            let img = new Image();
            if(typeof props.src == 'string') {
                img.src = props.src;
            }
            img.onload = () => {
                // @ts-ignore
                setStyle(props.src);
            }
            img.onerror = () => {
    
            }
        }
    }, [props.defaultSrc]);
    return (
        <div className="spd-bg-image" style={{
            backgroundImage: `url(${style})`,
            backgroundSize:'cover',
            backgroundPosition: 'center'
        }}></div>
    );
}